# frozen_string_literal: true

{{#generated_src_warning}}
{{generated_src_warning}}
{{/generated_src_warning}}

module {{module_name}}
  # @api private
  module ClientApi

    include Seahorse::Model

    {{#shapes}}
    {{name}} = {{class_name}}.new({{{constructor_args}}})
    {{/shapes}}

    {{#shape_definitions}}
    {{#lines}}
    {{{.}}}{{/lines}}

    {{/shape_definitions}}

    # @api private
    API = Seahorse::Model::Api.new.tap do |api|

      api.version = "{{api_version}}"

      api.metadata = {
        {{#metadata}}
        {{{key}}} => {{{value}}},
        {{/metadata}}
      }
      {{#endpoint_operation}}
      api.endpoint_operation = :{{endpoint_operation}}
      {{/endpoint_operation}}
      {{#require_endpoint_discovery}}
      api.require_endpoint_discovery = true
      {{/require_endpoint_discovery}}
      {{#operations}}

      api.add_operation(:{{method_name}}, Seahorse::Model::Operation.new.tap do |o|
        o.name = "{{name}}"
        o.http_method = "{{http_method}}"
        o.http_request_uri = "{{{http_request_uri}}}"
        {{#http_checksum_required}}
        o.http_checksum_required = true
        {{/http_checksum_required}}
        {{#http_checksum}}
        o.http_checksum = {
          {{#http_checksum}}
          {{{key}}} => {{{value}}},
          {{/http_checksum}}
        }
        {{/http_checksum}}
        {{#request_compression}}
        o.request_compression = {
          {{#request_compression}}
          {{{key}}} => {{{value}}},
          {{/request_compression}}
        }
        {{/request_compression}}
        {{#deprecated}}
        o.deprecated = true
        {{/deprecated}}
        {{#endpoint_operation}}
        o.endpoint_operation = true
        {{/endpoint_operation}}
        {{#endpoint_discovery_available}}
        o.endpoint_discovery = {
          {{#endpoint_discovery}}
          {{{key}}} => {{{value}}},
          {{/endpoint_discovery}}
        }
        {{/endpoint_discovery_available}}
        {{#authorizer}}
        o.authorizer = "{{authorizer}}"
        {{/authorizer}}
        {{#authtype}}
        o['authtype'] = "{{.}}"
        {{/authtype}}
        {{#unsigned_payload}}
        o['unsignedPayload'] = true
        {{/unsigned_payload}}
        {{#auth}}
        o['auth'] = {{&auth}}
        {{/auth}}
        {{#endpoint_trait}}
        o.endpoint_pattern = {
          {{#endpoint_pattern}}
          {{{key}}} => {{{value}}},
          {{/endpoint_pattern}}
        }
        {{/endpoint_trait}}
        {{#require_apikey}}
        o.require_apikey = {{require_apikey}}
        {{/require_apikey}}
        {{#shape_references}}
        {{#lines}}
        {{{.}}}{{/lines}}
        {{/shape_references}}
        {{#error_shape_names}}
        o.errors << Shapes::ShapeRef.new(shape: {{.}})
        {{/error_shape_names}}
        {{#pager}}
        {{#lines}}
        {{{.}}}{{/lines}}
        {{/pager}}
        {{#async}}
        o.async = true
        {{/async}}
      end)
      {{/operations}}
      {{#apig_authorizer}}

      api.add_authorizer(:{{authorizer_name}}, Seahorse::Model::Authorizer.new.tap do |a|
        a.name = "{{name}}"{{#type}}
        a.type = "{{type}}"{{/type}}{{#location}}
        a.placement = {
          :location => "{{location}}",
          :name => "{{location_name}}"
        }{{/location}}
      end)
      {{/apig_authorizer}}
    end

  end
end
